<%--
  Created by IntelliJ IDEA.
  User: argentum
  Date: 2018/11/29
  Time: 12:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <%@ include file="../base/top.jsp" %>
    <title>课程</title>
    <style>
        #result_admin{
            width: 90%;
            margin: auto;
            margin-top: 20px;
            padding: 20px;
            box-shadow: 0px 0px 3px #888888 ;
            border-radius: 5px;
            background-color: #FFFFFF;
        }
        .modal-dialog{
            z-index: 9999;
        }
    </style>
</head>

<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12" style="text-align: center">
                        <a class="btn btn-link" href="${talentTrainingProgramInfo.talentTrainingProgramAddress}" download="${talentTrainingProgramInfo.talentTrainingProgramName}${talentTrainingProgramInfo.talentTrainingProgramAddress.substring(talentTrainingProgramInfo.talentTrainingProgramAddress.indexOf("."),talentTrainingProgramInfo.talentTrainingProgramAddress.length())}"
                           style="font-size: 30px;  font-family: 宋体; background-repeat: no-repeat; margin-top: 20px;margin-bottom: 30px">
                            ${talentTrainingProgramInfo.talentTrainingProgramName}
                        </a>
                        <div id="result_admin">
                            <table id="data-table" width="90%" style="margin-left: 10%" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        全选<input type="checkbox" id="check-all"/>
                                    </th>
                                    <th>课程编号</th>
                                    <th>课程名</th>
                                    <th>开始学期</th>
                                    <th>学分</th>
                                    <th>学时</th>
                                    <th>课程类型</th>
                                    <th>考核方式</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                            <!--xxx()为要执行的操作-->
                            <button type="button" id="course" class="btn btn-warning" onclick="toAddCourse()">添加课程</button>

                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<%@ include file="../base/foot.jsp" %>
<script>
    var table = null;
    var columnsData =  [
        {
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
        },
        {'data': 'courseNum'},
        {'data': 'courseName'},
        {'data': 'courseStartTerm'},
        {'data': 'courseCredit'},
        {'data': 'courseHours'},
        {'data': 'courseType'},
        {'data': 'courseAssessmentMethod'},
        {
            bSortable : false,
            className : "text-center",
            width : "100px",
            render : function(data, type, row, meta) {
                var id = '"' + row.id + '"';
                var html = "";
                html += "<a href='javascript:void(0);' onclick='editCourse(this)' class='up btn btn-primary btn-xs'><i class='fa fa-arrow-up'></i> Edit</a> &nbsp;";
                html += "<a href='javascript:void(0);' onclick='deleteCourse(this)'  class='down btn btn-danger btn-xs'><i class='fa fa-arrow-down'></i> Delete</a>";
                return html;
            }
        }
    ];
    var parameter = {talentTrainingProgramId:"${talentTrainingProgramInfo.talentTrainingProgramId}"};
    var url='course/search_course_infos';
    $(document).ready(function() {
        table = $('#data-table').DataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION,{

            columns:columnsData,
            // ajax: {
            //     type: 'post',
            //     url: 'label/getList'
            // }
            ajax: function (data,callback) {
                ajax(data,callback,columnsData,url,parameter);
            }
        }));
    });

    function deleteCourse(button) {
        var json =getClickedRowValue(button);
        bootbox.confirm("确定要删除吗?", function(result) {
            if(result) {
                console.log(json['courseId'].replace(/\s+/g,""));
                $.post("<%=basePath%>course/dropCourse",
                    {courseId:json['courseId'].replace(/\s+/g,"")},
                    function(data){
                        if(data["success"]==true){
                            operateSuccess(data["msg"]);
                        }else if(data["success"]==false){
                            operateError(data["msg"]);
                        }
                    }
                );
            }
        });
    }


    function editCourse(button) {
        var courseInfo = getClickedRowValue(button);
        window.location.href = "course/toEditCourse?courseId="+courseInfo["courseId"];
    }
</script>

    <script>
        function toAddCourse() {
            var url ="course/toAddCourse?talentTrainingProgramId="+"${talentTrainingProgramInfo.talentTrainingProgramId}";
            addTab('2','1','添加课程',url);
        }
    </script>

</body>
</html>